<?php
namespace app\index\controller;

use app\BaseController;

use League\OAuth2\Client\Provider\GenericProvider;

use app\index\model\User as UserModel;

class Openid extends BaseController
{


    public function index()
    {
        

        $provider = new GenericProvider([
            'clientId'                => 'web_hxl',//
            'clientSecret'            => 'web_miyue',
            'redirectUri'             => 'http://127.1.1.1:8000/index/openid/url',//回调?
            'urlAuthorize'            => 'http://127.1.1.1:8000/index/oauth2/authorize',
            'urlAccessToken'          => 'http://127.1.1.1:8000/index/oauth2/token',
            'urlResourceOwnerDetails' => 'http://127.1.1.1:8000/index/oauth2/resource',
        ]);


        // dump($provider);

        if (!isset($_GET['code'])) {
            $authUrl = $provider->getAuthorizationUrl();
            $_SESSION['oauth2state'] = $provider->getState();
            header('Location: ' . $authUrl);
            exit;
        } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
            unset($_SESSION['oauth2state']);
            exit('Invalid state');
        }
        

    //    $UserModel = UserModel::where()->select();



        // return "openid";
        

    }

    public function url()
    {


    }

    
    
}
